//diag_log ["VAS Start Filling box",_this];
private ["_namespace","_event","_params","_box","_title","_val","_box_key","_box_extra"];

_box = objNull;
_box_key = "";
_box_extra = [];
if (count _this > 1) then {
	_params = _this select 1;
	if (typeName _params == typeName []) then {
		if (count _params > 0) then {_box = _params select 0; };
		if (count _params > 1) then { _box_key = _params select 1; };
		if (count _params > 2) then {_box_extra = _params select 2; };
	};
};
if (!isnil "_box") then {
	if (typename _box == typename objNull) then {
		if (!isnull _box) then {
			_val = _box getVariable "tonic_vas_ammo_box_initialized";
			if (isnil "_val") then {
				// START - SPECIAL FILLING OF THE AMMO BOX
				private ["_content","_content_name"];
				_content = nil;
				_content_name = "";
				if (typename _box_key != typename "") then { _box_key = str(_box_key); };
				switch (toupper(_box_key)) do {
					case "EAST": { _content = EAST_AMMO_BOX_CONTENT };
					case "WEST": { _content = WEST_AMMO_BOX_CONTENT };
					default {
						_content_name = Format["%1_AMMO_BOX_CONTENT",toupper(_box_key)];
						if (isNil _content_name) then {
							_content_name = switch (str(playerSide)) do {
								case "EAST":{ "EAST_AMMO_BOX_CONTENT" };
								default { "WEST_AMMO_BOX_CONTENT" };
							};
						};
						_content = missionNameSpace getVariable [_content_name,[]];
					};
				};
				if (!isNil "_content" && {typename _content == typename []} && {count _content > 0}) then {
					private ["_weapons","_magazines","_items","_backpacks","_goggles","_x"];
					//diag_log ["VAS Loading custom content",_content_name,count _content];
					_weapons = [];
					_magazines = [];
					_items = [];
					_backpacks = [];
					_goggles = [];
					{
						if ((typename _x == typename []) && {(count _x > 1)}) then {
							switch ((_x select 0)) do {
								case 0: { if (isClass(configFile/"CfgMagazines"/(_x select 1))) then { _magazines set [count _magazines, (_x select 1)]; };};
								case 1: { if (isClass(configFile/"CfgWeapons"/(_x select 1))) then { _weapons set [count _weapons, (_x select 1)]; };};
								case 2: { if (isClass(configFile/"CfgWeapons"/(_x select 1))) then { _items set [count _items, (_x select 1)]; };};
								case 3: { if (isClass(configFile/"CfgVehicles"/(_x select 1))) then { _backpacks set [count _backpacks, (_x select 1)]; };};
								case 4: { if (isClass(configFile/"CfgGlasses"/(_x select 1))) then { _goggles set [count _goggles, (_x select 1)]; };};
							};
						};
					} foreach _content;
					//diag_log ["VAS Loading custom content",_content_name,count _weapons,count _magazines,count _items,count _backpacks,count _goggles];
					
					_box setVariable["bis_weapons",_weapons];
					_box setVariable["bis_magazines",_magazines];
					_box setVariable["bis_items",_items];
					_box setVariable["bis_backpacks",_backpacks];
					_box setVariable["bis_goggles",_goggles];
				};
				// END - SPECIAL FILLING OF THE AMMO BOX
			
				_title = "<t color='#ff1111'>" + localize "STR_ACTION_VAS" + "</t>";
				_val = _box addAction[_title, "tmf\support\modules\tonic_vas\open.sqf",_this,100,true, false,"","alive _target"];
				clearItemCargoGlobal _box;
				clearWeaponCargoGlobal _box;
				clearMagazineCargoGlobal _box;
				_box setVariable ["tonic_vas_ammo_box_initialized",_val];
				//diag_log ["VAS End Filling box",_val];
			};
		};
	};
};
// We return an array with true to indicate we did something. the ExecHandler expects an array of results.
[true]